package pl.smath.expression.model.presentation;

import pl.smath.expression.model.Term;

public class ExtendedRelationTerm extends PresentationTerm {
	
	/** Lewe wyrazenie */
	private final Term leftTerm;
	/** Prawe wyrazenie */
	private final Term rightTerm;
	/** typ */
	private ExtendedRelationType relationType;
	
	public ExtendedRelationTerm(String type, Term left, Term right) {
		super(type);
		relationType = ExtendedRelationType.string2type(type);
		this.leftTerm = left;
		this.rightTerm = right;
	}

	/**
	 * typ relacji
	 */
	public ExtendedRelationType getRelationType(){
		return relationType;
	}
	
	public Term getLeftTerm() {
		return leftTerm;
	}

	public Term getRightTerm() {
		return rightTerm;
	}

	/**
	 * Sprawdzenie czy 2 wartości bezwgledne wyrazenia sa sobie równowazne.
	 */
	public boolean isAbsTheSame(Term term){
		if (!(term instanceof ExtendedRelationTerm))
			return false;
		
		ExtendedRelationTerm ert = (ExtendedRelationTerm)term; 
		
		if (ert.getRelationType() != getRelationType())
			return false;
		
		if (!ert.getLeftTerm().isAbsTheSame(getLeftTerm())  ||  !ert.getRightTerm().isAbsTheSame(getRightTerm()))
			return false;
		
		return true;
	}
	public String toString(){
		return getLeftTerm().toString() + ExtendedRelationType.type2string(relationType) + getRightTerm().toString(); 
	}
}
